<?php

class CategoriesController extends AppController {

  var $helpers = array("Html","Text","Javascript","Ajax");
  
  function index() {
		App::import('Model', 'Product');
		$p = new Product();
    $cats = $this->Category->findAll();
		foreach($cats as $cid => $cat) {
			$cats[$cid]['Category']['total'] = 0;
			foreach($cat['Subcategory'] as $sid => $subcat) {
				$num = $p->findCount('Product.subcategory_id = ' . $subcat['subcategory_id'] . " and Product.donotlist = '0' and Producer.donotlist_producer = '0'");
				$cats[$cid]['Category']['total'] += $num;
				$cats[$cid]['Subcategory'][$sid]['total'] = $num;
			}
		}
		$this->set('cats',$cats);
    $this->render();
  }
  
  function view() {
  	$this->redirect('/categories/index');
  }

}

?>
